/* 
 * Author: anand
 * 
 */


#include "folder.h"

dbhelper * folder::_dbhelper = dbhelper::get_helper();
int	folder::save(const char *path_)
{
	_path = path_;
	std::string sql = FOLDER_GET_SQL;
	sql.replace(sql.find("?"),1,path_);
	result_set * result = _dbhelper->get_row_map(sql.c_str());
	if(result->size())
	{
		_id = atoi( (*(result->at(0)))["id"].c_str());
	}
	else
	{
		_id = _dbhelper->get_id(FOLDER_TABLE_NAME);
		std::string savesql = FOLDER_INSERT_SQL;
		savesql.replace(savesql.find("?"),1,path_util::convert_to_string(_id));
		savesql.replace(savesql.find("?"),1,_path);
		_dbhelper->raw_execute(savesql.c_str());
	}

	return _id;
}

